# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ngs
pkgver=0.2.12
pkgrel=1
pkgdesc="Next Generation Shell"
url="https://ngs-lang.org"
# tests fail on disabled arches
arch="all !armhf !armv7 !s390x !x86"
license="GPL-3.0"
makedepends="bash cmake gc-dev json-c-dev libffi-dev pcre-dev peg"
subpackages="$pkgname-aws::noarch $pkgname-vim::noarch"
source="https://github.com/ngs-lang/ngs/archive/v$pkgver/ngs-$pkgver.tar.gz
	cmakelists.patch
	busybox-compat.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		$CMAKE_CROSSOPTS .
	make -C build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE NGS_PATH="$builddir/lib" ctest
}

package() {
	make -C build install DESTDIR="$pkgdir"

	# stdlib.ngs is bundled into the ngs binary, so it's not used.
	cd "$pkgdir"/usr/lib/ngs
	rm -rf experiments lang-tests.ngs stdlib.ngs
}

aws() {
	pkgdesc="$pkgdesc - experimental AWS library"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/ngs/autoload/globals/AWS*
}

vim() {
	pkgdesc="$pkgdesc (vim syntax)"
	depends=""
	install_if="vim $pkgname=$pkgver-r$pkgrel"

	mkdir -p "$subpkgdir"/usr/share/vim/vimfiles
	cp -r "$builddir"/vim/* "$subpkgdir"/usr/share/vim/vimfiles/
}

sha512sums="
7946448787526f1981acea37810ca5eec8d57a0f44ae7a3219b525663cd628e2d41840fb0426333dde5b3750d6183d475809e0fa1de76e41d4fb6a8cba61b652  ngs-0.2.12.tar.gz
e0f2c590ecb2d354671e0db7ddef725a2b7aa5201a93db6ae387f46bdcd956d71a66bb54309c6d9a1407b7cb500ccbbb2e0ade4e2a04a1ab721596791b051fb4  cmakelists.patch
a3c22590c2ba072eab773859d9fa50c55d88f8f7af5d70c0ddb4bd005d69a549f87625d5da47f515256ef004bdae2f2366e427c63b16a4f9471eca3effdec0cd  busybox-compat.patch
"
